import java.util.PriorityQueue;

public class Solution {


    public static void main(String[] args) {
//        int[] nums = {100,100,100,-250,-60,-140,-50,-50,100,150};
        int[] nums = {-10715,70330,-86814,47156,-30228,43981,33837,18381,6608};
        System.out.println(magicTower(nums));
    }
    public static int magicTower(int[] nums) {
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        long sum = 1, last = 0;
        int res = 0, room;
        for (int num : nums) {
            sum += num;
            if (num < 0) {
                pq.add(num);
            }
            if (sum <= 0) {
                room = pq.poll();
                sum -= room;
                last += room;
                res++;
            }
        }
        if (sum + last <= 0) return -1;
        return res;
    }
}
